package com.burial.common.config;


import com.burial.common.utils.LoginInterceptor;
import com.burial.common.utils.RefreshTokenInterceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;
import java.util.List;

//@Configuration
public class MvcConfig implements WebMvcConfigurer {

    private static final Logger logger = LoggerFactory.getLogger(MvcConfig.class);


    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //token刷新拦截器
        logger.info("Adding RefreshTokenInterceptor...");
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
        logger.info("RefreshTokenInterceptor added.");

        //拦截器
        logger.info("添加日志前");
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/doc.html/**",
                        "/swagger-resources/**",
                        "/**/v2/api-docs" ,
                        "/webjars/**"
                ).order(1);
        logger.info("添加日志");
    }
}
